package com.wwwarehouse.contract.create_warehouse_map;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.MotionEvent;
import android.view.View;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.bean.response.CardDeskFunctionResponseBean;
import com.wwwarehouse.common.constant.Constant;
import com.wwwarehouse.contract.bean.ListCreateWarehouseMapBean;
import com.wwwarehouse.contract.core.BaseViewPagerFragment;
import com.wwwarehouse.contract.core.ContractConstant;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by feng.gao on 2017/10/17.
 * 创建仓库地图的左滑右滑页面
 */
@Route(path = "/contract/CreateWarehouseMapViewpager")
public class CreateWarehouseMapViewpager extends BaseViewPagerFragment {
	private String mBusinessId;

	@Override
	public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		mConfirmBtn.setVisibility(View.GONE);
		mCustomScroll.setOnTouchListener(new View.OnTouchListener() {
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				return true;
			}
		});

	}
	@Override
	public void onResponse(final String response, int what) {
		if (what == 1) {
			ListCreateWarehouseMapBean bean = JSON.parseObject(response, ListCreateWarehouseMapBean.class);
			bean.setmBusinessId(mBusinessId);
			if (bean.getList() != null && bean.getList().size() > 0) {
				setData(bean, bean.getTotal(), 9, CreateWarehouseMapGridFragment.class.getName());
			} else {
				mStateLayout.showEmptyView(true);
				mStateLayout.setEmptyListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						requestDatas();
					}
				});
			}
		}


	}

	@Override
	public void setTitle() {
		if (peekFragment() instanceof CreateWarehouseMapViewpager) {
			mActivity.setTitle("修改仓库地图");
		}
	}

	@Override
	public void requestDatas() {
		if (getArguments() != null && getArguments().getSerializable(Constant.KEY_CARD_DESK_FUNCTION_DETAILS) != null) {
			CardDeskFunctionResponseBean.TaskBean taskBean = (CardDeskFunctionResponseBean.TaskBean) getArguments().getSerializable(Constant.KEY_CARD_DESK_FUNCTION_DETAILS);
			if (taskBean != null) {
				mBusinessId = taskBean.getBusinessId();
				Map<String, Object> map = new HashMap<>();
				map.put("page", 1);
				map.put("size", 99999);
				Map<String, Object> paramsMap = new HashMap<>();
				paramsMap.put("businessUnitId", mBusinessId);
				paramsMap.put("query", map);
				paramsMap.put("userId", sp.getValue(Constant.sp_User_Id));
				sendRequest(ContractConstant.IMPORT_MAP_PAGINATION , paramsMap , 1);

			}
		}



	}
}
